package com.aaa.tmr.controller;

import com.aaa.tmr.entity.Dept;
import com.aaa.tmr.service.DeptService;
import com.aaa.tmr.util.Result;
import com.aaa.tmr.util.ReturnStatus;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 部门表(Dept)表控制层
 *
 * @author makejava
 * @since 2021-03-19 10:33:51
 */
@Controller
@RequestMapping("dept")
public class DeptController {
    /**
     * 服务对象
     */
    @Resource
    private DeptService deptService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Dept selectOne(Integer id) {
        return this.deptService.queryById(id);
    }

    @RequestMapping("toPage")
    public String toPage(){
        return "back/deptPage";
    }

    /**
     * 分页查询dept
     * @param page 起始页
     * @param limit 条数
     * @param dept 参数
     * @return Result<java.util.List>
     */
    @RequestMapping("queryAll")
    @ResponseBody
    public Result<java.util.List> queryAll(Integer page, Integer limit, Dept dept){
        PageInfo pageInfo = deptService.queryAll(page, limit, dept);

        return new Result<>(ReturnStatus.SUCCESS.getCode(),ReturnStatus.SUCCESS.getMessage()
                ,pageInfo.getTotal(),pageInfo.getList());
    }

    /**
     * description: 部门添加方法
      * @param dept 部门
     * @return Result<Dept>
     * @author Marko
     * @Date 2021/3/21 17:14
     **/
    @PostMapping("insert")
    @ResponseBody
    public Result<Dept> insert(Dept dept){
        return new Result<>(ReturnStatus.SUCCESS.getCode(),ReturnStatus.SUCCESS.getMessage()
                ,0L,deptService.insert(dept));
    }

    /**
     * description: 部门更新方法
     * @param dept 部门
     * @return Result<Dept>
     * @author Marko
     * @Date 2021/3/21 18:14
     **/
    @PutMapping("update")
    @ResponseBody
    public Result<Dept> update(Dept dept){
        return new Result<>(ReturnStatus.SUCCESS.getCode(),ReturnStatus.SUCCESS.getMessage()
                ,0L,deptService.update(dept));
    }

    /**
     * description: 部门删除方法
     * @param deptId 部门deptId
     * @return Result<Dept>
     * @author Marko
     * @Date 2021/3/21 18:14
     **/
    @DeleteMapping("deleteById")
    @ResponseBody
    public Result<Boolean> deleteById(Integer deptId){
        return new Result<>(ReturnStatus.SUCCESS.getCode(),ReturnStatus.SUCCESS.getMessage()
                ,0L,deptService.deleteById(deptId));
    }

    /**
     * description: 部门删除方法
     * @param deptIds deptIds
     * @return Result<Integer>
     * @author Marko
     * @Date 2021/3/21 18:14
     **/
    @DeleteMapping("deleteByIds")
    @ResponseBody
    public Result<Integer> deleteByIds(String deptIds){
        return new Result<>(ReturnStatus.SUCCESS.getCode(),ReturnStatus.SUCCESS.getMessage()
                ,0L,deptService.deleteByIds(deptIds));
    }
}
